package org.compiere.model;

import java.util.Properties;

import org.compiere.apps.IProcessParameter;
import org.compiere.apps.ProcessCtl;
import org.compiere.apps.ProcessParameterPanel;
import org.compiere.process.ProcessInfo;
import org.compiere.util.ASyncProcess;
import org.compiere.util.CLogger;
import org.compiere.util.DB;

public class Mcmsagreement extends X_cms_agreement implements ASyncProcess {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4634364153490671173L;
	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (Mcmsagreement.class);
	
	public Mcmsagreement(Properties ctx, int cms_agreement_ID, String trxName) {
		super(ctx, cms_agreement_ID, trxName);
	}
	
	/**
	 * 	After Save
	 *	@param newRecord new
	 *	@param success success
	 *	@return success
	 */
	protected boolean afterSave (boolean newRecord, boolean success)
	{
		if(this.isSign_Y())
			return true;
		X_CMS_Contract c = new X_CMS_Contract(getCtx(), this.getCMS_Contract_ID(), get_TrxName());
		c.setcms_statusestype_ID(X_cms_statusestype.CMS_OnAgreement);
		
		int ad_process_id = getProcess();
		ProcessInfo pi = new ProcessInfo("Inform Agreement", ad_process_id, this.get_Table_ID(), this.get_ID());
		pi.setAD_Client_ID(this.getAD_Client_ID());
		pi.setAD_User_ID(this.getAD_User_ID());
		
		ProcessParameterPanel pu = new ProcessParameterPanel(0, pi);
		ProcessCtl.process(this, 0, (IProcessParameter) pu, pi, null);
		//ProcessCtl.pr

		return success;
	}	//	afterSave

	private int getProcess()
	{
		String sql = "select ad_process_id from ad_process where lower(name) like '%cms_informagreement%'";
		
		int ad_process_id = DB.getSQLValue(get_TrxName(), sql);
		
		return ad_process_id;
	}
	
	@Override
	public void lockUI(ProcessInfo pi) {
	}

	@Override
	public void unlockUI(ProcessInfo pi) {
	}

	@Override
	public boolean isUILocked() {
		return false;
	}

	@Override
	public void executeASync(ProcessInfo pi) {
	}

}
